<!-- 更新弹窗 -->
<template>
	<view>
		<view class="updatePage" v-if="lengthThe<100&&lengthThe>0">
			<view class="updatePageBg"></view>
			<view class="promptBox">
				<image src="./movingGraph.gif" mode="aspectFit"></image>
				<view class="clues">正在下载({{lengthThe}}%)</view>
				<view class="progressBar">
					<view class="progressOf" :style="{'width':lengthThe+'%'}"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:'updatePage',
		data() {
			return {
				lengthThe:0,
			};
		},
		mounted() {
			
		},
		// onLoad() {
		// 	this.$emit('onReady')
		// },
		methods:{
			detectionUpdate(){
				console.log('detectionUpdate')
				// return;
				// #ifdef APP-PLUS
				let _this = this;
				plus.runtime.getProperty(plus.runtime.appid, wgtinfo => {
					console.log(wgtinfo.version); //应用版本号
					_this.$http.request('/dbxs/post/reward/link_query', {}).then(res => {
						console.log(res);
						if (wgtinfo.version != res.data[0].param_value) {
							uni.showModal({
								confirmText: '更新',
								content: '检测到新版本，要更新么？',
								title: '提示',
								success(e) {
									if (e.confirm) {
										// console.log("res",res,"e",e)
										var url = res.data[1].param_value; // 下载文件地址
										var options = { method: 'GET' };
										var dtask = plus.downloader.createDownload(url, options);
										
										dtask.addEventListener('statechanged', function(task, status) {
											switch (task.state) {
												case 1: // 开始
													break;
												case 2: //已连接到服务器
													break;
												case 3: // 已接收到数据
													var current = parseInt((100 * task.downloadedSize) / task.totalSize);
													_this.lengthThe = current;
													// console.log('已下载' + current + '%');
													break;
												case 4:
													// uni.hideLoading();
													plus.runtime.install(
														task.filename, //安装APP
														{
															force: true
														},
														function() {},
														function() {
															_this.$toast('更新失败了', 'none');
														}
													);
													break;
											}
										});
				
										dtask.start();
									}
								}
							});
						}
					});
				});
				
				// #endif
			}
		}
		
	}
</script>

<style lang="scss">
	.updatePage{
		width: 100vw;
		height: 100vh;
		position: fixed;
		left: 0rpx;
		top: 0rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 9999;
		.updatePageBg{
			width: 100vw;
			height: 100vh;
			// background-color: #111111;
			position: absolute;
			top: 0rpx;
			left: 0rpx;
		}
		.promptBox{
			width: 50vw;
			height: 50vw;
			opacity: 1;
			background-color: #151515;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			border-radius: 50rpx;
			image{
				width: 30vw;
				height: 30vw;
			}
			.clues{
				color: #EEEEEE;
				font-size: 30rpx;
				margin: 20rpx 0rpx;
			}
			.progressBar{
				width: 40vw;
				height: 1.5vw;
				background-color: #AAAAAA;
				border-radius: 5rpx;
				.progressOf{
					height: 1.5vw;
					width: 20vw;
					background-color: #EEEEEE;
				}
			}
		}
	}
</style>
